package com.efounder.view;

import android.app.Activity;
import android.app.ProgressDialog;
import android.view.Window;

/**
 * 全局loading 框
 */
public class GlobalLoadingDialog {

    protected boolean cancelable = true;
    protected String message;
    protected int stringResId;
    protected Activity context;
    private ProgressDialog dialog;

    public GlobalLoadingDialog(Activity context) {
        this.context = context;
        dialog = new ProgressDialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }

    public void setCancelable(boolean cancelable) {
        this.cancelable = cancelable;
        dialog.setCancelable(cancelable);
    }

    public void showLoading(String text) {
        if (dialog != null && dialog.isShowing()) {
            dialog.setMessage(text);
            return;
        }
        dialog.setMessage(text);
        dialog.show();

    }

    public void dismissLoading() {
        if (dialog != null && dialog.isShowing() && !context.isDestroyed()) {
            dialog.dismiss();
        }
    }

    public boolean isShowing() {
        if (dialog == null) {
            return false;
        }
        return dialog.isShowing();
    }


}
